// 封装prisma数据模型

import {PrismaClient} from "@prisma/client"

declare global {
    namespace NodeJS {
        interface Global {
            prisma: PrismaClient
        }
    }
}

let prisma: PrismaClient;

if (process.env.ENV === 'production') {
    // 如果是生产环境只实例化一次
    prisma = new PrismaClient();
} else {
    // 测试环境
    if (!global.prisma) {
        global.prisma = new PrismaClient();
    }

    prisma = global.prisma;
}

export default prisma